//
//  GGZFBBusinessCell.m
//  Gunterapple
//
//  Created by 热带雨林 on 2020/4/2.
//  Copyright © 2020 热带雨林. All rights reserved.
//

#import "GGZFBBusinessCell.h"
#import "GGZFBBusinessModel.h"
#import "GGAddtion.h"
#import "GGZFBStartLevelView.h"
@interface GGZFBBusinessCell ()
@property (nonatomic, weak)UIImageView *icon;
@property (nonatomic, weak)UILabel *nameLab;
@property (nonatomic, weak)UILabel *priceLabel;
@property (nonatomic, weak)UILabel *distanceLabel;
@property (nonatomic, weak) GGZFBStartLevelView *startView;
@end

@implementation GGZFBBusinessCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self setUpUI];
    }
    return self;
}
- (void)setUpUI{
    UIImageView *icon = [[UIImageView alloc]initWithFrame:CGRectZero];
    self.icon = icon;
    [self.contentView addSubview:icon];
  
    UILabel *nameLab = [[UILabel alloc]init];
    self.nameLab = nameLab;
    self.nameLab.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
    [self.nameLab sizeToFit];
    [self.contentView addSubview:self.nameLab];
    
    UILabel *priceLabel = [[UILabel alloc]init];
    [self.contentView addSubview:priceLabel];
    self.priceLabel = priceLabel;
    priceLabel.font = [UIFont systemFontOfSize:14];
    [self.priceLabel sizeToFit];
    
    UILabel *distanceLabel = [[UILabel alloc]init];
    [self.contentView addSubview:distanceLabel];
    self.distanceLabel = distanceLabel;
    self.distanceLabel.font = [UIFont systemFontOfSize:14];
    [self.distanceLabel sizeToFit];
    
    GGZFBStartLevelView *startView = [[GGZFBStartLevelView alloc]initWithFrame:CGRectZero];
    self.startView = startView;
    [self.contentView addSubview:self.startView];
    
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
          make.top.left.equalTo(self.contentView).offset(20);
          make.bottom.equalTo(self.contentView.mas_bottom).offset(-20);
          make.size.mas_equalTo(CGSizeMake(80, 80));
    }];
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.icon);
        make.left.equalTo(self.icon.mas_right).offset(20);
        make.width.lessThanOrEqualTo(@200);//宽度小于等于200
    }];
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLab.mas_bottom).offset(10);
        make.left.equalTo(self.nameLab);
    }];
    [self.distanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.priceLabel.mas_right).offset(10);
        make.top.equalTo(self.priceLabel);
    }];
    [self.startView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.icon.mas_bottom);
        make.left.equalTo(self.icon.mas_right).offset(20);
        make.size.mas_equalTo(CGSizeMake(70, 14));
    }];
}
- (void)setModel:(GGZFBBusinessModel *)model{
    _model = model;
    self.icon.image = [UIImage imageNamed:model.icon];
    self.nameLab.text = model.name;
    self.priceLabel.text = [NSString stringWithFormat:@"人均消费%.2f",model.averagePrice];
    self.distanceLabel.text = [NSString stringWithFormat:@"距您%.fm",model.distance];
    self.startView.level = model.level;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
